package com.bankcomm.ui.specialwidget;

import com.rytong.tools.ui.Component;
import com.rytong.tools.ui.LPSelect;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

/**
 * 该类为搜索框组合控件，最外层为一�?横向线形结构布局，主要用于添加背景图片�?横向线形布局包含的是该控件的主体：一个自动完整文字域和一个按钮域
 * 
 * @author Boston
 * 
 */
public class LPAutoCompleteTextView extends Component {
    final int AlertWidth_ = 250;
    int align_;
    // 暂定存储50条客联想内容
    final int maxSize_ = 50;
    // 自动联想输入控件的最小高�?
    final int minHeight_ = 50;
    // 联想字符串，该字符串内容从内存中读取
    private static String[] autoStr_;
    // 自动提示输入控件适配器对�?
    ArrayAdapter<String> adapter_;
    // 自动填充输入控件
    // private MultiAutoCompleteTextView mulAutoText_;
    LPAutoText mulAutoText_;

    /**
     * @author Chris
     * 
     */
    class LPAutoText extends EditText {

        public LPAutoText(final Context context) {
            super(context);
            this.setText("");
            this.setWidth(LPAutoCompleteTextView.this.AlertWidth_);
            // 添加内容改变监听
            this.addTextChangedListener(new TextWatcher() {

                @Override
                public void afterTextChanged(Editable arg0) {
                    String text = arg0.toString();
                    if ((null != text) || !text.equals(""))
                        BOCSearchView.doSearch(context, text);
                }

                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // TODO Auto-generated method stub

                }

            });
        }

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            super.onKeyDown(keyCode, event);
            // 当用户移动轨迹球时，不执行查�?操作，相应控�??��始操???

            switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                this.setText("");
                if (LPSelect.ISPOPING)
                    LPSelect.ISPOPING = false;
                return super.onKeyDown(keyCode, event);
            default:
                return super.onKeyDown(keyCode, event);
            }
        }

    }

    /**
     * @author Chris
     * 
     */
    class LPSearchButton extends Button {

        public LPSearchButton(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }

    }

    /**
     * @author Chris
     * 
     */
    public class MyLPAutoCompleteTextView extends LinearLayout {

        public MyLPAutoCompleteTextView(Context context) {
            super(context);
        }

        public Component composited() {
            // TODO Auto-generated method stub
            return LPAutoCompleteTextView.this;
        }

    }

    public LPAutoCompleteTextView(Activity bv) {
        realView_ = new MyLPAutoCompleteTextView(bv);
        // 初始化自动填充输入控�?
        // mulAutoText_ = new MultiAutoCompleteTextView(context);
        mulAutoText_ = new LPAutoText(bv);
        // restAdapter(getSourceString());
        // 设置分词器，逗号分割，允许用户增加新的选择�?
        // mulAutoText_
        // .setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
        // 设置自动联想控件为单行显�?
        mulAutoText_.setSingleLine();
        // 设置输第一个字符就开始提�?
        // mulAutoText_.setThreshold(1);

        // 设置搜索按钮控件的点击效�?

        MyLPAutoCompleteTextView autoCompleteLayout = new MyLPAutoCompleteTextView(bv);
        // 自动填充输入控件加入横向布局
        autoCompleteLayout.addView(mulAutoText_);

    }

    protected String[] getRecord() {
        return autoStr_;
    }

    // 取得自动联想输入控件的内�?
    public String getText() {
        return mulAutoText_.getText().toString();
    }

    @Override
    public void setContentText(String text) {
        mulAutoText_.setText(text);
    }

    @Override
    public void mouldW() throws Exception {
        // TODO Auto-generated method stub
    }

    @Override
    public void mouldH() throws Exception {
        // TODO Auto-generated method stub
    }

    @Override
    public void initRealView(Activity activity, String value) {
        // TODO Auto-generated method stub
        realView_ = new MyLPAutoCompleteTextView(activity);
    }

}
